import 'package:flutter/material.dart';

class GridList extends StatefulWidget {
  final List dataSource;

  const GridList({Key key, this.dataSource}) : super(key: key);
  @override
  _GridListState createState() => _GridListState();
}

class _GridListState extends State<GridList> {
  Widget _createItem(BuildContext context, Map item) {
    return InkWell(
      onTap: () {
        print('object${item['name']}');
      },
      child: Column(
        children: [
          Image.asset(item['pic'], height: 40, width: 40),
          Padding(
            padding: const EdgeInsets.only(top: 5),
            child: RichText(
              text: TextSpan(
                text: item['name'],
                style: TextStyle(
                  color: Colors.black,
                ),
              ),
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
            ),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GridView.count(
      physics: NeverScrollableScrollPhysics(),
      crossAxisCount: 5,
      shrinkWrap: true,
      padding: EdgeInsets.all(5.0),
      mainAxisSpacing: 10,
      crossAxisSpacing: 5,
      children: widget.dataSource.map((e) {
        return _createItem(context, e);
      }).toList(),
    );
  }
}
